﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace Projektarbete
{
    class Tile
    {
        protected ushort textureID;
        public ushort getTextureID { get { return textureID; } set { textureID = value; } }

        protected byte drawRow;
        public byte getDrawRow { get { return drawRow; } }
        protected byte drawColumn;
        public byte getDrawColumn { get { return drawColumn; } }

        protected bool blocksVision;
        public bool BlocksVision { get { return blocksVision; } }

        /// <summary>
        /// Creates a tile class
        /// </summary>
        /// <param name="textureID">Which texture to draw</param>
        /// <param name="blocksVision">Does this tile block vision</param>
        public Tile(ushort textureID, bool blocksVision)
        {
            this.textureID = textureID;
            this.blocksVision = blocksVision;

            drawColumn = (byte)Math.Floor((double)textureID / 10);
            drawRow = (byte)(textureID % 10);
        }

        /// <summary>
        /// Updates the drawColumn and drawRow of this tile based on the current texture
        /// </summary>
        public void UpdateDraw()
        {
            //NET-TODO: send updated textures

            drawColumn = (byte)Math.Floor((double)textureID / 10);
            drawRow = (byte)(textureID % 10);
        }

        /// <summary>
        /// Updates this tile's texture
        /// </summary>
        /// <param name="drawRow">new drawRow. Set to 0 for unchanged</param>
        /// <param name="drawColumn">new drawColumn. Set to 0 for unchanged</param>
        public void UpdateTexture(byte drawRow, byte drawColumn)
        {
            //NET-TODO: send updated textures

            if(drawRow != 0)
                this.drawRow = drawRow;
            if(drawColumn != 0)
                this.drawColumn = drawColumn;
        }

        /// <summary>
        /// Gets data from this tile (if there is any)
        /// USE WITH CARE
        /// </summary>
        public virtual TileData GetData()
        {
            return new TileData();
        }

        /// <summary>
        /// Sets this tile's data (if there is any)
        /// </summary>
        public virtual void SetData(TileData data)
        {

        }

        /// <summary>
        /// Interact with the selected tile
        /// </summary>
        public virtual bool Interact()
        {
            return false;
        }
    }
}
